package minh.bac.wcbrazil2014.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteHelper extends SQLiteOpenHelper {

	private static MySQLiteHelper mMySQLiteHelper;
	public final static String NAME_DB = "WC2014";
	public final static String NAME_TABLE_DOIBONG = "tb_doibong";
	public final static String NAME_TABLE_VONBANG = "tb_vongbang";
	public final static String NAME_TABLE_VONGDAU = "tb_vongdau";
	public final static String NAME_TABLE_XEPHANG = "tb_xephang";
	public static int VERSION = 1;
	// doibong
	public static String doiBong = "doibong";
	public static String bangDau = "bangdau";
	public static String thuMon = "thumon";
	public static String hauVe = "hauve";
	public static String tienVe = "tienve";
	public static String tienDao = "tiendao";
	public static String tuCachThamDu = "tucachthamdu";
	public static String xepHangFiFa = "xephangfifa";
	public static String lichSuThamDu = "lichsuthamdu";
	public static String favorite = "favorite";

	// vongbang
	public static String tran = "tran", ngay = "ngay", gio = "gio",
			doi1 = "doi1", imgLinkDoi1 = "imglinkdoi1", score1 = "score1",
			doi2 = "doi2", imgLinkdoi2 = "imglinkdoi2", score2 = "score2",
			diaDiem = "diadiem", kenhTV = "kenhtv";
	// vong dau
	public static String vong = "vongdau";
	// xếp hạng
	public static String image = "image", thb = "thb", hieuso = "hieuso",
			diem = "diem";

	// ------------------------------------------------------------------------------------------------------------------------------------------------
	// -------------------------------------------------------Create
	// Table-----------------------------------------------------------------------------
	public static String CREATE_TABLE_DOIBONG = "create table "
			+ NAME_TABLE_DOIBONG + " ( " + doiBong + " text not null ,"
			+ bangDau + " text ," + thuMon + " text ," + hauVe + " text , "
			+ tienVe + " text , " + tienDao + " text , " + tuCachThamDu
			+ " text , " + xepHangFiFa + " text , " + lichSuThamDu + " text , "
			+ favorite + " Integer " + ");";
	// -------------------------------------------------------------------------------------------------------------------------------------------
	public static String CREATE_TABLE_VONGBANG = "create table "
			+ NAME_TABLE_VONBANG + " ( " + bangDau + " text not null ," + tran
			+ " text ," + ngay + " text ," + gio + " text , " + doi1
			+ " text , " + imgLinkDoi1 + " text , " + score1 + " text , "
			+ doi2 + " text , " + imgLinkdoi2 + " text , " + score2
			+ " text , " + diaDiem + " text , " + kenhTV + " text  " + ");";
	// -----------------------------------------------------------------------------------------------------------------------------------------------
	public static String CREATE_TABLE_VONGDAU = "create table "
			+ NAME_TABLE_VONGDAU + " ( " + vong + " text not null ," + tran
			+ " text ," + ngay + " text ," + gio + " text , " + doi1
			+ " text , " + imgLinkDoi1 + " text , " + score1 + " text , "
			+ doi2 + " text , " + imgLinkdoi2 + " text , " + score2
			+ " text , " + diaDiem + " text , " + kenhTV + " text  " + ");";
	// -----------------------------------------------------------------------------------------------------------------------------------------------
	public static String CREATE_TABLE_XEPHANG = "CREATE TABLE "
			+ NAME_TABLE_XEPHANG + " ( " + bangDau + " text not null , "
			+ doiBong + " text , " + image + " text , " + tran + " text , "
			+ thb + " text , " + hieuso + " text , " + diem + " text " + ");";

	// ------------------------------------------------------------------------------------------------------------------------------------------------
	/*
	 * this is singleton sqlitehelpter return 1 object mysqlitehelper
	 */
	public static MySQLiteHelper getInstance(Context context) {
		if (mMySQLiteHelper == null) {
			mMySQLiteHelper = new MySQLiteHelper(context, NAME_DB, null,
					VERSION);
		}
		return mMySQLiteHelper;
	}

	public MySQLiteHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(CREATE_TABLE_DOIBONG);
		db.execSQL(CREATE_TABLE_VONGBANG);
		db.execSQL(CREATE_TABLE_VONGDAU);
		db.execSQL(CREATE_TABLE_XEPHANG);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

}
